<?
        require_once '../inc/functions.php';
        require_once dirname(__FILE__) . '/data.php';
        require_once dirname(__FILE__) . '/../Users/data.php';
        require_once dirname(__FILE__) . '/../Lookups/data.php';
        $section='Users';
        
        if(isset($_REQUEST['PName']))
        {
                $rs = $_REQUEST;
                $errors = Validate($rs);
                if(!$errors)
                        $errors = Save2($rs);
                if(!$errors)
                {
                        header("Location: index.php?new_id=$rs[id]");
                }
        }
        elseif(isset($_REQUEST['id']))
                $rs = Get($_REQUEST['id']);
        else
                $rs = Blank();

	
        $resultSizes = Sizes::GetAll();  
        $resultColors = Colors::GetAll();        
        $resultsUesrs = Users::GetAll();
        $resultsLookups = Lookups::GetAll();
?>

<!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Users</title>
        <style type="text/css">
                        .error { color: red; }
                        input.error {
                                border: 1px solid red;
                                background: #FEE;
                        }
                </style>
    </head>
    
    <body>
                <? include("../inc/tabs.php"); ?>
        <div id="container">
        <h1>Buy a Product</h1>
        <ul class="error">
                <? foreach($errors as $field => $error){ ?>
                <li><?=$field?>: <?=$error?></li>
            <? } ?>
        </ul>
        
    <form method="post" action="">
                <label>id:</label>
                <?=$rs['id']?>
            <br />     

<label for="User_id">User:</label>
            <select size="1" name="User_id" id="User_id"
                    class="<?=isset($errors['User_id']) ? 'error' : '' ?>" >
                <? while($rsUsers = $resultsUesrs->fetch_assoc()){ ?>
                    <option value="<?=$rsUsers['id']?>" 
                                <? if($rsUsers['id'] == $rs['User_id']){ ?>
                                selected="selected"
                            <? } ?>
                    >
              <?=$rsUsers['FirstName']?> <?=$rsUsers['LastName']?>
                     </option>
                                <? } ?>
            </select>
            <span class="error"><?=$errors['User_id']?></span>
            <br />	

	

<label for="PName">Product Name</label>
                <input  type="text"
                        name="PName" id="PName"
                    value="<?=$rs['PName']?>"
                    class="<?=isset($errors['PName']) ? 'error' : '' ?>" />
            <span class="error"><?=$errors['PName']?></span>
            <br />

	<label for="Supplier">Supplier</label>
                <input  type="text"
                        name="Supplier" id="Supplier"
                    value="<?=$rs['Supplier']?>"
                    class="<?=isset($errors['Supplier']) ? 'error' : '' ?>" />
            <span class="error"><?=$errors['Supplier']?></span>
            <br />




	<label for="Size">Size:</label>
                <select name="Size" id="Size"
                    class="<?=isset($errors['Size']) ? 'error' : '' ?>" >
                <? while($rsLookups = $resultsLookups->fetch_assoc()){ ?>
                    <option value="<?=$rsLookups['id']?>" 
                                <? if($rsLookups['id'] == $rs['Size']){ ?>
                                selected="selected"
                            <? } ?>
                    >
                                                <?=$rsLookups['Name']?>
                     </option>
                                <? } ?>
                        </select>
            <span class="error"><?=$errors['Lookup_id']?></span>
            <br />

		



<label for="Color">Color</label>
                <input  type="text"
                        name="Color" id="Color"
                    value="<?=$rs['Color']?>"
                    class="<?=isset($errors['Color']) ? 'error' : '' ?>" />
            <span class="error"><?=$errors['Color']?></span>
<p>  1=Red    2=Orange   3=Yellow   4=Green   5=Blue </p>
<br/>

            <input type="submit" value="Save" />
        </form>
        </div>
        </body>
</html>
